package com.example.spring_trans.service;

import com.example.spring_trans.mapper.LogInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/25
 * Time: 13:24
 */
@Service
@Slf4j
public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper;

    @Transactional(propagation = Propagation.NESTED)
    public void insertLog(String name, String op) {
        // 记录用户操作
        logInfoMapper.insertLog(name, "用户注册");
        try {
            int a = 10 / 0;
        } catch (Exception e) {
            // 回滚当前事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }
}
